# -*- encoding: utf-8 -*-
'''
@File    :   Response.py   
@Contact :   desufnocs@163.com
@des     :   响应
 
@Modify Time       @Author      @Version    @Desciption
------------      ----------    --------    -----------
2025/2/17 12:39   AssenImpact      1.0         None
'''


def base_response(code: int, msg: str, data: any = None):
    """
    基本响应模板
    :param code:状态码
    :param data:返回数据
    :param msg:返回消息
    :return:{code,msg,data}
    """
    if not data:
        data = []
    return {
        "code": code,
        "msg": msg,
        "data": data
    }


def success(data: any = None, msg: str = ""):
    """
    成功返回响应
    :param data:返回数据
    :param msg:返回消息
    :return: {code,msg,data}
    """
    return base_response(code=200, msg=msg, data=data)


def fail(code: int = 400, data: any = None, msg: str = ""):
    """
    失败返回响应
    :param code:状态码
    :param data:返回数据
    :param msg:返回消息
    :return:{code,msg,data}
    """
    return base_response(code=code, msg=msg, data=data)
